package com.qmgyl.marketshop.api;


import java.util.List;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.qmfresh.service.shop.facade.dto.InstockQuery;
import com.qmfresh.service.shop.facade.dto.ShopTimeQuery;
import com.qmgyl.marketshop.common.HttpUtils;
import com.qmgyl.marketshop.vo.ListWithPage;
import com.qmgyl.marketshop.vo.ProcurementOrderInstockResult;
import com.qmgyl.marketshop.vo.ProcurementOrderItem;
import com.qmgyl.marketshop.vo.ServiceResult;

public class StockServiceApi {
	
	private String serviceUrl;
	
	
	public String getServiceUrl() {
		return serviceUrl;
	}

	public void setServiceUrl(String serviceUrl) {
		this.serviceUrl = serviceUrl;
	}

	/**
	 * 获取入库单列表
	 * @param orderQuery
	 * @return
	 */
	public ListWithPage<ProcurementOrderInstockResult> getList(ShopTimeQuery shopTimeQuery){
		String result = HttpUtils.postRequestBody(serviceUrl + "/instock/list",shopTimeQuery);
		System.out.println(result);
		ServiceResult<ListWithPage<ProcurementOrderInstockResult>> sr = JSONObject.parseObject(result, new TypeReference<ServiceResult<ListWithPage<ProcurementOrderInstockResult>>>(){});
		return sr.getBody();
	}
	
	/**
	 * 修改item
	 * @param shopTimeQuery
	 * @return
	 */
	public String changeItem(InstockQuery instockQuery){
		String result = HttpUtils.postRequestBody(serviceUrl + "/instock/updateInstockItem",instockQuery);
		System.out.println(result);
		return result;
	}
	
	/**
	 * 获取可以入库的商品
	 * @param instockQuery
	 * @return
	 */
	public List<ProcurementOrderItem> getNeedInstock(InstockQuery instockQuery){
		String result = HttpUtils.postRequestBody(serviceUrl + "/instock/getNeedInstock",instockQuery);
		System.out.println(result);
		ServiceResult<List<ProcurementOrderItem>> sr=JSONObject.parseObject(result, new TypeReference<ServiceResult<List<ProcurementOrderItem>>>(){});
		return sr.getBody();
	}
	
	
	/**
	 * 创建出库单
	 * @param instockQuery
	 * @return
	 */
	public String createStock(InstockQuery instockQuery){
		String result = HttpUtils.postRequestBody(serviceUrl + "/instock/createStock",instockQuery);
		System.out.println(result);
		return result;
	}

}
